$(function(){
		$("#patientTable").datagrid({
			pagination:true,
			toolbar:'#tb',
			idField:"id"
		})
	})
	function addressFormatter(value,row,index){
			return row.address.name;
	}
	function patientSetCondition(){
		var postData = {name:$("#name").val()}
		var ids = $("#address").combobox("getValue");
		postData["address.id"] = ids;
		$("#patientTable").datagrid("reload",postData);
	}
	function genderFormatter(value,row,index){
		var a = "";
		if(value==1){
			a="男"
		}else{
			a="女"
		}
		return a;
	}
	function imageFormatter(value,row,index){
		if(row.image!=null){
			return "<img src='"+row.image+"' alt='' width='50' height='50' />";			
		}
	}
	
	//添加病人档案
	function addPatient(){
		addDialog("添加病人档案",950,500,"patient/patientfrom","#patientForm","patient/patientAdd","#patientTable");
	}
	
	
	//修改病人档案
	function editPatient(){
		var row = $("#patientTable").datagrid("getSelected");
		if(row==null){
			$.messager.alert("提示","请选择要修改的数据行","warning");
			return;
		}
		$("#patientTable").datagrid("clearSelections");
		$("#patientTable").datagrid("selectRecord",row.id);
		var d = $("<div></div>").appendTo("body");
		d.dialog({
			title:"修改病人档案",
			iconCls:"icon-edit",
			width:950,
			height:500,
			modal:true,
			href:"patient/patientfrom",
			onClose:function(){$(this).dialog("destroy");},
			onLoad:function(){
				$.post("patient/selectPatientById",{id:row.id},function(data){
					$("#patientForm").form("load",data);
					$("#qu").combobox("select",data.address.id);
					$("#preview").attr("src",data.image);
				})
			},
			buttons:[{
				iconCls:"icon-ok",
				text:"确定",
				handler:function(){
					$("#patientForm").form("submit",{
						url:"patient/patientEdit",
						success:function(data){
							d.dialog("close");
							$("#patientTable").datagrid("reload");
							
						}
					})
				}
			},{
				iconCls:"icon-cancel",
				text:"取消",
				handler:function(){
					d.dialog("close");
				}
			}]
			
		})
	}
	
	//删除病人档案
	function deletePatient(){
		deleteConfirm("#patientTable","patient/deletePatient");
	}